import {
    DIC
} from '@/const/dic';
import {
    parseTime,
} from '../formatter';
import provinces from "@/data/province";

function validateGreaterZeroWrapper(field) {
    return (rule, value, callback) => {
        if (value <= 0) {
            callback(new Error(field + '必须大于0'));
        } else {
            callback();
        }
    };
}
const validateGreaterZero = (rule, value, callback) => {
    if (value <= 0) {
        callback(new Error('商品价格必须大于0'));
    } else {
        callback();
    }
};
export const taskTableOption = {
    border: true,
    index: true,
    selection: true,
    calcHeight: 350,
    tip: false,
    columnBtn: false,
    height: "auto",
    searchClearable: false,
    selectClearBtn: false,
    clearable: false,
    menu: true,
    menuAlign: "center",
    searchBtn: true,
    labelWidth: 120,
    refreshBtn: true,
    addBtn: true,
    dialogWidth: '800px',
    dialogHeight: 'auto',
    menuWidth: 180,
    editBtn: true,
    viewBtn: false,
    delBtn: true,
    column: [{
            "label": "商家店铺名",
            "prop": "ShopName",
            "search": true,
            "type": "text",
            "fixed": false,
            "width": 140,
            "row": false,
            "readonly": false,
            "span": 24,
            "display": true,
            "rules": [{
                "required": true,
                "message": "请输入商家店铺名",
                "trigger": "blur"
            }]
        },
        {
            "label": "商品名称",
            "prop": "GoodsName",
            "search": true,
            "type": "text",
            "fixed": false,
            "width": 300,
            "row": false,
            "readonly": false,
            "span": 24,
            "display": true,
            "rules": [{
                "required": true,
                "message": "请输入商品名称",
                "trigger": "blur"
            }]
        },
        {
            "label": "商品图片",
            "prop": "GoodsCover",
            "search": false,
            "type": "upload",
            "fixed": false,
            "width": 140,
            "row": false,
            "readonly": false,
            "span": 12,
            "listType": "picture-img",
            "showFileList": false,
            action: '/upload/image',
            "tip": "只能上传jpg/png文件，且不超过500kb",
            "display": true,
            "rules": [{
                "required": true,
                "message": "请上传商品图片",
                "trigger": "blur"
            }]
        },

        {
            "label": "商品价格",
            "prop": "Price",
            "search": false,
            "type": "number",
            precision: 2,
            "fixed": false,
            "width": 100,
            "row": false,
            "readonly": false,
            "span": 12,
            "display": true,
            "rules": [{
                "required": true,
                "message": "请输入商品价格",
                "trigger": "blur"
            }, {
                validator: validateGreaterZero,
                trigger: 'blur'
            }]
        },
        {
            "label": "地区要求",
            "prop": "Area",
            "search": true,
            "type": "select",
            multiple: true,
            "fixed": false,
            "width": 200,
            "readonly": false,
            dicData: provinces,
            props: {
                label: 'label',
                value: 'value'
            },
            "span": 12,
            "display": true,
            "rules": [{
                "required": false,
                "message": "请输入地区",
                "trigger": "blur"
            }]
        },
        {
            "label": "性别要求",
            "prop": "Sex",
            "search": false,
            "type": "radio",
            dicData: DIC.sex,
            "fixed": false,
            "width": 100,
            "row": false,
            "readonly": false,
            "span": 12,
            "display": true,
            "rules": [{
                "required": true,
                "message": "请选择性别要求",
                "trigger": "blur"
            }]
        },
        {
            "label": "任务状态",
            "prop": "Status",
            "search": true,
            "type": "tag",
            "fixed": false,
            "width": 90,
            "row": false,
            "readonly": false,
            "span": 12,
            "display": false,
            "dicData": DIC["taskStatus"]
        },
        {
            "label": "产品链接",
            "prop": "GoodsLink",
            "search": false,
            "type": "text",
            "fixed": false,
            "minWidth": "350",
            "row": false,
            "readonly": false,
            "span": 24,
            "display": true,
            "rules": [{
                "required": true,
                "message": "请输入产品链接",
                "trigger": "blur"
            }]
        },

        {
            "label": "最低价格",
            "prop": "MinPrice",
            "search": false,
            "type": "number",
            precision: 2,
            "fixed": false,
            "width": "160",
            "row": false,
            "minWidth": "120",
            "readonly": false,
            "span": 12,
            "display": true,
            "rules": [{
                "required": true,
                "message": "请输入最低价格",
                "trigger": "blur"
            }, {
                validator: validateGreaterZeroWrapper('最低价格'),
                trigger: 'blur'
            }]
        },
        {
            "label": "大约付款人数",
            "prop": "BuyerNum",
            "search": false,
            "type": "number",
            "fixed": false,
            "width": "160",
            "row": false,
            "minWidth": "120",
            "readonly": false,
            "span": 12,
            "display": true,
            "rules": [{
                "required": true,
                "message": "请输入大约付款人数",
                "trigger": "blur"
            }, {
                validator: validateGreaterZeroWrapper('大约付款人数'),
                trigger: 'blur'
            }]
        },
        {
            "label": "库存位置",
            "prop": "StockPos",
            "search": false,
            "type": "text",
            "fixed": false,
            "width": "160",
            "row": false,
            "minWidth": "120",
            "readonly": false,
            "span": 12,
            "display": true,
            "rules": [{
                "required": true,
                "message": "请输入库存位置",
                "trigger": "blur"
            }]
        },
        {
            "label": "商家要求",
            "prop": "ShopRequirement",
            "search": false,
            "type": "textarea",
            "fixed": false,
            "width": "300",
            "row": 4,
            "minWidth": "120",
            "readonly": false,
            "span": 24
        },
        {
            "label": "搜索关键字",
            "prop": "Keywords",
            formslot: true,
            "search": false,
            "type": "text",
            "fixed": false,
            "width": "auto",
            "row": false,
            "minWidth": "120",
            "readonly": false,
            "span": 24,
            "display": true,
            hide: true,
            "rules": [{
                "required": true,
                'type': 'array',
                "message": "请添加搜索关键字",
                "trigger": "blur"
            }]
        },
        {
            "label": "发送频率",
            "prop": "Publishes",
            formslot: true,
            "search": false,
            "type": "text",
            "fixed": false,
            "width": "auto",
            "row": false,
            "minWidth": "120",
            "readonly": false,
            "span": 24,
            "display": true,
            hide: true,
            "rules": [{
                "required": true,
                'type': 'array',
                "message": "请添加发送频率",
                "trigger": "blur"
            }]
        },
        {
            "label": "创建时间",
            "prop": "CreateTime",
            "search": false,
            "type": "datetime",
            "fixed": false,
            "width": "160",
            "row": false,
            "minWidth": "120",
            formatter: parseTime,
            "readonly": false,
            "span": 12,
            "display": false
        },
        {
            "label": "修改时间",
            "prop": "ModifyTime",
            "search": false,
            "type": "datetime",
            "fixed": false,
            formatter: parseTime,
            "width": "160",
            "row": false,
            "minWidth": "120",
            "readonly": false,
            "span": 12,
            "display": false
        }
    ]
};
